#include<iostream>
using namespace std;
#include<cmath>
#include<iomanip>

#include"library.h"

#define exact 1.15288726707017

double y(double x){
	if(fabs(x)<1E-9){
		cout<<"invalid input for y(x): |x|<1E-9"<<endl;
		exit(1);
	}
	return sin(1/x/x);
}

int main(){

	double epsilon = 1E-10;
	double a = 0.1, b = 10;
	double z1 = SelfAdapt_Simpson(a,b,y,epsilon);
	cout<<setprecision(15)<<"SelfAdapt_Simpson: error="<<z1-exact<<"\t";

	double z2;
	cout<<"Simpson:"<<endl;
	for(int i=0;i<8;i++){
		z2 = Simpson(a,b,pow(10,i),y);
		cout<<"h="<<1/pow(10,i)<<"\t\t";
		cout<<pow(10,i)<<" grids\t";
		cout<<"error="<<z2-exact<<endl;
	}

	return 0;
}
		
